<SCRIPT LANGUAGE="JavaScript"> 
    var xx = 100;
    var yy = 100;
    var tx = 0;
    var ty = 0;
    var dx = 0;
    var dy = 0;
    var klik = 0;
    
    function make_slip(event)
    {  
        if(event)
        {
            xx=event.clientX;
            yy=event.clientY;
        }
        else
        {
            xx=100;
            yy=100;
        }
        klik=0;
        
        var temp = document.getElementById('slip');
        temp.style.position = 'absolute';
        temp.style.borderTop = '4px solid #ddd';
        temp.style.borderLeft = '4px solid #ddd';
        temp.style.borderBottom = '4px solid #aaa';
        temp.style.borderRight = '4px solid #aaa';
            
        temp.style.top = yy+'px';
        temp.style.left = xx+'px';
        temp.style.width = 'auto';
        temp.style.height = 'auto';
        temp.style.backgroundColor = 'white';
    }
    
    function close_slip()
    {  
        document.getElementById('slip').innerHTML = '';
        document.getElementById('slip').style.border = 'none';
    }
    
    function tekan(event)
    {
        klik = 1;
        tx=event.clientX;
        ty=event.clientY;
    }
    
    function gerak(event)
    {
        if(klik==1)
        {
            dx=event.clientX-tx;
            dy=event.clientY-ty;
            
            xx = xx + dx;
            yy = yy + dy;
            
            document.getElementById('slip').style.top = yy+'px';
            document.getElementById('slip').style.left = xx+'px';      
            
            tx=event.clientX;
            ty=event.clientY;
        }
    }    
    
    function lepas()
    {
        klik=0;
    }

    function swap(id)
    {
        var temp = "page"+id;
        document.getElementById('search_result').innerHTML = document.getElementById(temp).innerHTML;
    }   

    var baseurl = '';    
    function open_win2(id)
    {
        baseurl = document.getElementById('baseurl').value;
        window.open(baseurl+'jobs/view/'+id,"_blank","toolbar=no, location=yes, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=yes, top=100, left=100, width=930, height=600");
    }    
    
    function open_win(id)
    {
        baseurl = document.getElementById('baseurl').value;
        window.open(baseurl+'employers/view/'+id,"_blank","toolbar=no, location=yes, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=yes, top=100, left=100, width=930, height=600");
    }     
    
    
    
</SCRIPT>

<?php
$baseurl = current(split("app/webroot", $_SERVER['PHP_SELF']));
echo "<input type='hidden' value='".$baseurl."' id='baseurl'>";
echo $this->Element('myfunction');
echo "<div class='form'>"; 
echo "<h2> Job Search Result </h2>";
echo "<hr color='#2A7EF7'>";  
echo ":. Start new job search ".$html->link('[ Job Search ]',array('controller'=>'jobs','action'=>'search'))."<br />";

    $max_record = RECORD_PER_PAGE;
    $jum_record = count($jobs);
    $page = floor($jum_record / $max_record);
    if($jum_record % $max_record != 0)
    { $page++; }
    $record = 0;
    
    echo "<br />&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp <b>.: Job Search Result :.</b>";
    echo "<div id='search_result'>";
    if(count($jobs)==0)
    { echo "&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp <span class='red'>* There is no job that match to your search</span>"; }
    echo"</div>";
    for($i=1; $i<=$page; $i++)
    {
        echo "<div id='page".$i."' style='display:none'>";
        echo "<table class='jobs' cellpadding=0 cellspacing=0 style='margin-top:3px'>";
        echo "<tr><th width='100px'>Posted Date</th><th width='220px'>Position</th><th width='150px'>Company Name</th><th width='120px'>Location</th><th width='100px'>Career Level</th><th width='80px'>Year Exp</th><th width='120px'>Salary</th><th width='120px'>Action</th></tr>";
        for ($j=0; $j<$max_record; $j++)
        {
            if( $record < $jum_record )
            {
                echo "<tr>";
                    echo "<td>".mydate($jobs[$record]['jobs']['created'])."</td>";
                    //echo "<td>".$html->link($jobs[$record]['jobs']['position'], array('controller' => 'jobs','action' => 'view','id' => $jobs[$record]['jobs']['id']))."</td>";
                    echo "<td> <a href='javascript:open_win2(".$jobs[$record]['jobs']['id'].")' class='sky'>".$jobs[$record]['jobs']['position']."</a> &nbsp";

                    //echo "<td>".$jobs[$record]['employers']['company_name']."</td>";
                    echo "<td><a href='javascript:open_win(".$jobs[$record]['employers']['id'].")'>".$jobs[$record]['employers']['company_name']."</a></td>";
                    echo "<td>".$jobs[$record]['cities']['name']."</td>";                      
                    if($jobs[$record]['jobs']['entry']==1)
                    echo "<td>Entry Level</td>";
                    if($jobs[$record]['jobs']['middle']==1)
                    echo "<td>Middle</td>";
                    if($jobs[$record]['jobs']['senior']==1)
                    echo "<td>Senior</td>";
                    if($jobs[$record]['jobs']['top']==1)
                    echo "<td>Top</td>";

                    echo "<td>".$jobs[$record]['jobs']['experience']."</td>";
                    if($jobs[$record]['jobs']['salary']==0)
                    { echo "<td>".SALARY_0."</td>"; }
                    if($jobs[$record]['jobs']['salary']==1)
                    { echo "<td>".SALARY_1."</td>"; }
                    if($jobs[$record]['jobs']['salary']==2)
                    { echo "<td>".SALARY_2."</td>"; }
                    if($jobs[$record]['jobs']['salary']==3)
                    { echo "<td>".SALARY_3."</td>"; }
                    if($jobs[$record]['jobs']['salary']==4)
                    { echo "<td>".SALARY_4."</td>"; } 
                    
                    //echo "<td>".$ajax->link('[ Apply ]', array('controller'=>'applicants','action'=>'apply_ajax',$jobs[$record]['jobs']['id']), array('update'=>'slip','complete'=>"make_slip();"));
                    if($_SESSION['User']['type']=='jobseeker')
                    {
                        echo "<td>".$html->link('[ Apply Now ]',array('controller'=>'applicants','action'=>'apply',$jobs[$record]['jobs']['id']));                 
                        $baseurl = current(split("index", $_SERVER['PHP_SELF']));
                        echo " &nbsp".$html->link("<img src='".$baseurl."img/clipboard2.gif'>", array('controller'=>'clipboards','action'=>'save',$jobs[$record]['jobs']['id']),array(),false,false);
                        echo "</td>";
                    }
                    else
                    { echo "<td>&nbsp</td>"; }
                       
                echo "</tr>";
                $record++;
            }
        }
        
        echo "<tr class='end'>";
        if($page!=1)
        {
            if($i==1)
            { echo "<td class='end' colspan=7> </td><td style='text-align:right' class='end'><a href='javascript:swap(".($i+1).")'>Next >></a> &nbsp</td>"; }

            if($i!=1 && $i!=$page)
            { 
                echo "<td class='end'>&nbsp <a href='javascript:swap(".($i-1).")'><< Prev</a></td>"; 
                echo "<td class='end' style='text-align:right' colspan=7><a href='javascript:swap(".($i+1).")'>Next >></a> &nbsp</td>";
            }
            
            if($i==$page)
            { echo "<td class='end' colspan=7>&nbsp <a href='javascript:swap(".($i-1).")'><< Prev</a></td><td class='end'> </td>"; }
        }        
        else
        { echo "<td class='end' colspan=8> &nbsp </td>"; }
        echo "</tr>";
        echo "</table>";
        echo "</div>";
    }    

echo "</div>";
echo "<div id='slip'></div>";
?>

<SCRIPT LANGUAGE="JavaScript"> 
        document.getElementById('search_result').innerHTML = document.getElementById('page1').innerHTML;
</SCRIPT>